<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.saving}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            
            <h:form prependId="false" >
               <script type="text/javascript">  
                    var doInitForm=false;
                    var tofocus;
                   
                    function changeFocus(nextfcs) {tofocus=nextfcs;}
                    function setDoInitForm(st) {doInitForm=st;}
                    
                    function focusState(xhr, status, args) {  
                       if(args.validationFailed || !args.success) {}
                       else document.getElementById(tofocus).focus();
                       return false;
                    }
                   
                    function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                            
                        }else 
                            setTimeout(function() {
                                if (doInitForm==true) btnNewSaving.jq.click();  
                            }, 3000);
                    }
                
                    function customRK(e, id, nextfcs) {
                      var code = (e.keyCode ? e.keyCode : e.which);
                       if(code==13) {
                            if (id=="savingCIF") rcsavingGetCustomer();
                            else if (id=="savingJointCust") rcsavingGetJointCust();
                            else if (id=="savingJointCust1") rcsavingGetJointCust1();
                            
                            tofocus=nextfcs;
                            e.preventDefault ? e.preventDefault() : e.returnValue = false;
                            e.stopPropagation();
                       }
                    }
                    
                </script>  
               
                <p:remoteCommand name="rcsavingGetCustomer" actionListener="#{savingBean.getSavingCustomer('null')}" 
                                 process="savingCIF @this" update="hideSavingCustomerId savingJoinAccnt"  oncomplete="focusState(xhr, status, args);" />
                <p:remoteCommand name="rcsavingGetJointCust" actionListener="#{savingBean.getJointCustomer('null')}" 
                                 update="savjoinCustname" /> 
                
                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" widgetVar="btnNewSaving"
                                         action="#{savingBean.newData()}" oncomplete="setDoInitForm(false);" 
                                         rendered="#{menuBean.cekButtonAccess(101,'INS;')}"
                                         update="displaySaving submitSaving" process="@this">
                            <pe:resetEditableValues for="displaySaving"/>  
                        </p:commandButton>  
                                                                                            
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" disabled="#{!savingBean.editMode}"
                                         id="submitSaving"
                                         rendered="#{menuBean.cekButtonAccess(101,'INS;')}"
                                         action="#{savingBean.trySave()}" oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);" 
                                         update="displaySaving, @this" >
                        </p:commandButton> 
                    </p:toolbarGroup>
                    
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingSaving" type="button" value="" style="width: 0px; height: 0px;"/> 
                        <p:defaultCommand target="#{savingBean.defaultButton}"/> 
                    </p:toolbarGroup>
                    
                    <!-- -->
                </p:toolbar>
<!--                </p:outputPanel>    -->
               
                <!-- LOOK UP CUSTOMER -->
                <p:dialog header="#{bundle.Select} #{bundle.customer}" widgetVar="dlgSavLookupCust" closable="true" dynamic="true" >
                    <p:ajax listener="#{savingBean.handleCloseLookup}" />
                    <h:panelGrid id="displaySavingLookup" rendered="#{savingBean.showLookup==true}">
                    
                        <ui:include src="../master/customer/searchCustomer.xhtml" >
                            <ui:param name="lookupCustComponenId" value="saving" />
                        </ui:include> 

                        <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR" id="footSavLookupCust">
                            <f:facet name="footer">
                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" immediate="true" rendered="#{savingBean.searchSatus == 1}"
                                                process="@this" update="savingCIF, hideSavingCustomerId savingJoinAccnt"
                                                action="#{savingBean.getSavingCustomer(searchCustomer.selectedData.cif)}" 
                                                oncomplete="dlgSavLookupCust.hide(); focusState(xhr, status, args);" />

                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" immediate="true" 
                                                rendered="#{savingBean.searchSatus == 2}"
                                                process="@this" update="savjoinCustname savingJointCust" 
                                                action="#{savingBean.getJointCustomer(searchCustomer.selectedData.cif)}" 
                                                oncomplete="dlgSavLookupCust.hide()" />

                                <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgSavLookupCust.hide()" immediate="true" icon="ui-icon-document" process="@this" />
                            </f:facet>
                        </h:panelGrid>
                    </h:panelGrid>    
                </p:dialog>
                
                                 
                <h:panelGrid id="displaySaving" styleClass="addELIT" cellpadding="0" border="0">
                    <h:panelGrid style="vertical-align: top" columns="2" cellpadding="1" rowClasses="panelGridId" border="0" columnClasses="panelGridId,panelGridId">
                        <p:panel header="#{bundle.savledgend}" style="margin: 0 0 0 0;" >
                            <h:panelGrid columns="3" border="0" cellpadding="0" cellspacing="10" >
                                <p:outputLabel value= "#{bundle.cif}" for="savingCIF"/><h:outputLabel value=":" />
                                <h:panelGrid columns="3" cellpadding="0" cellspacing="0">
                                    <p:inputText value="#{savingBean.saving.customer.cif}" style="width: 142px;"
                                        onkeydown="customRK(event, 'savingCIF', '#{utilityBean.findClientId('savingSaprodId')}')" id="savingCIF" label="#{bundle.cif}"
                                        requiredMessage="#{bundle.cif} #{bundle.requiredInput}"
                                        required="true" disabled="#{!savingBean.editMode}">
                                    </p:inputText>
                                    
                                    <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall"
                                                     update="displaySavingLookup footSavLookupCust" onclick="changeFocus('#{utilityBean.findClientId('savingSaprodId')}');"
                                                     process="@this" immediate="true" oncomplete="dlgSavLookupCust.show();" disabled="#{!savingBean.editMode}">
                                        <f:setPropertyActionListener value="#{1}" target="#{savingBean.searchSatus}" />  
                                        <f:setPropertyActionListener target="#{savingBean.showLookup}" value="#{true}" />
                                    </p:commandButton>
                                </h:panelGrid>
                                                             
                                <p:outputLabel value="#{bundle.savprod}" for="savingSaprodId"/><h:outputLabel value=":"/>
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                    <p:selectOneMenu value="#{savingBean.saving.savprod}" style="width: 170px;"
                                                     id="savingSaprodId" label="#{bundle.savprod}" 
                                            requiredMessage="#{bundle.savprod} #{bundle.requiredInput}" 
                                            required="true" disabled="#{!savingBean.editMode}" var="prod" converter="savprod">
                                        <f:selectItem rendered="#{savingBean.saving.savprod!=null}" itemLabel="#{savingBean.saving.savprod.productName}" itemValue="#{savingBean.saving.savprod}" />
                                        <f:selectItems value="#{savingBean.avaibleProduct}" var="p" itemLabel="#{p.productName}" itemValue="#{p}" />
                                        <p:column>#{prod.productNo}</p:column>
                                        <p:column>#{prod.productName}</p:column>
                                        <p:ajax update="savingAccNo savSaprodInfo" listener="#{savingBean.handleProdChange}" />  
                                    </p:selectOneMenu>
                                </h:panelGrid>

                                <h:outputLabel value="#{bundle.openDate}" /><h:outputLabel value=":"/>
                                <h:outputText value="#{savingBean.saving.openDate}" />
                                
                                <p:outputLabel value= "#{bundle.savingNo}" for="savingAccNo" /><h:outputLabel value=":"/>
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <p:inputText value="#{savingBean.saving.accountNo}" 
                                        onkeydown="customRK(event, '', '')" id="savingAccNo" style="width: 169px;" label="#{bundle.accountNo}"
                                        requiredMessage="#{bundle.accountNo} #{bundle.requiredInput}"
                                        required="false" disabled="#{!savingBean.editMode}">
                                        <p:ajax event="blur" listener="#{savingBean.handleNumberChange}" process="@this"/>
                                    </p:inputText>
                                </h:panelGrid>

                                <h:outputLabel style="padding: 0 15px 0 0;" value= "#{bundle.savpurpose}" /><h:outputLabel value=":"/>
                                <p:selectOneMenu value="#{savingBean.saving.savpurpose.savpurposeId}" style="width: 170px;" disabled="#{!savingBean.editMode}">
                                    <f:selectItems value="#{savingBean.avaiblePurpose}" var="purpose" 
                                                   itemLabel="#{purpose.purposeName}" itemValue="#{purpose.savpurposeId}" />
                                </p:selectOneMenu>

                                <h:outputLabel value="#{bundle.joinAccnt}" /><h:outputLabel value=":"/>
                                <p:selectBooleanCheckbox value="#{savingBean.saving.joinAccnt}" 
                                     disabled="#{savingBean.saving.customer.customerId==null or savingBean.editMode==false}" id="savingJoinAccnt" >
                                    <p:ajax process="@this" update="savingJoinType dtSavjointss" />
                                </p:selectBooleanCheckbox>

                                <h:outputLabel value="#{bundle.joinType}" /><h:outputLabel value=":"/>
                                <p:selectOneRadio value="#{savingBean.saving.joinType}" id="savingJoinType" style="margin: 0 0 0 -3px;" 
                                                  disabled="#{not savingBean.saving.joinAccnt or savingBean.editMode==false}" >
                                    <f:selectItem itemLabel="#{bundle.joinTypeAnd}" itemValue="A" />
                                    <f:selectItem itemLabel="#{bundle.joinTypeOr}" itemValue="O" />
                                </p:selectOneRadio>
                                
                                <h:inputHidden value="#{savingBean.saving.customer.customerId}" id="hideSavingCustomerId"
                                    required="true" requiredMessage="#{bundle.cif} #{bundle.requiredInput}" />
                            </h:panelGrid>
                            
                            <p:panel>
                            <pe:masterDetail id="savjointmd" selectLevelListener="#{selectLevelListener.handleNavigation}" style="width: 400px;" >
                                
                                <pe:masterDetailLevel level="1" levelLabel="#{bundle.joinAccnt}" >
                                    <p:outputPanel autoUpdate="true">
                                        <p:dataTable id="dtSavjointss" var="savjoin" value="#{savingBean.saving.savjoints}" >
                                        <p:column style="width:100px">
                                            <f:facet name="header">#{bundle.cif}</f:facet>
                                            <h:outputText value="#{savjoin.customer.cif}"/>
                                        </p:column>
                                                                                
                                        <p:column style="width:auto" >
                                            <f:facet name="header">#{bundle.globalName}</f:facet>
                                            <h:outputText value="#{savjoin.customer.customerName}"/>
                                        </p:column> 
                                        
                                        <p:column style="width:90px" >
                                            <f:facet name="header">Actions</f:facet>
                                            
                                            <p:commandLink value="Add" actionListener="#{savingBean.newJoint()}" disabled="#{!savingBean.saving.joinAccnt or savingBean.editMode==false}">
                                                <pe:selectDetailLevel contextValue="#{null}" preserveInputs="true"/>
                                            </p:commandLink><p:spacer width="3"/>
                                            
                                            <p:commandLink value="Edit" actionListener="#{savingBean.editJoint(savjoin)}" 
                                                           disabled="#{!savingBean.saving.joinAccnt or savingBean.editMode==false or savjoin.customer.customerId == null}">
                                                <pe:selectDetailLevel contextValue="#{savjoin}" preserveInputs="true"/>
                                            </p:commandLink><p:spacer width="3"/>
                                            
                                            <p:commandLink value="Del" actionListener="#{savingBean.handleRemoveRow}" 
                                                           disabled="#{!savingBean.saving.joinAccnt or savingBean.editMode==false or savjoin.customer.customerId == null}">
                                                <p:collector value="#{savjoin}" removeFrom="#{savingBean.saving.savjoints}" />  
                                            </p:commandLink>
                                        </p:column>
                                     </p:dataTable>
                                     </p:outputPanel>
                                </pe:masterDetailLevel>   
                                                              
                                <pe:masterDetailLevel level="2" levelLabel="Add/edit" contextVar="savjoin">
                                    <h:panelGrid id="frmSavjoindetail" columns="3" border="0" cellpadding="0" cellspacing="10">
                                        <h:outputLabel value= "#{bundle.cif}" /><h:outputLabel value=":"/>
                                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                            <p:inputText value="#{savingBean.unsaveJoint.customer.cif}" style="width: 146px;"
                                                onkeydown="customRK(event, 'savingJointCust', '')" label="#{bundle.cif}"
                                                requiredMessage="#{bundle.cif} #{bundle.requiredInput}" id="savingJointCust" >
                                                <p:ajax update="msgsavingJoinCIF" process="@this"/>
                                            </p:inputText>
                                            
                                            <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall" update="footSavLookupCust" process="@this" 
                                                             oncomplete="dlgSavLookupCust.show();" >
                                                <f:setPropertyActionListener value="#{2}" target="#{savingBean.searchSatus}" />  
                                                <f:setPropertyActionListener target="#{savingBean.showLookup}" value="#{true}" />
                                            </p:commandButton>
                                            
                                            <p:message id="msgsavingJoinCIF" for="savingJointCust" display="icon" />
                                        </h:panelGrid>
                                                                            
                                        <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value=":"/>
                                        <h:outputText value="#{savingBean.unsaveJoint.customer.customerName}" id="savjoinCustname" />
                                    </h:panelGrid>
                                    
                                    <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                                        <f:facet name="footer">  
                                            <p:commandButton value="Back" icon="ui-icon ui-icon-arrowthick-1-w" process="@this">
                                                <pe:resetEditableValues for="frmSavjoindetail"/>  
                                                <pe:selectDetailLevel step="-1"/>
                                            </p:commandButton>
                                            
                                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{savingBean.saveJoint()}"/>
                                            
                                            <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" actionListener="#{savingBean.newJoint()}"  
                                                             process="@this" update="frmSavjoindetail">
                                                <pe:resetEditableValues for="frmSavjoindetail"/>  
                                            </p:commandButton>  
                                            
                                        </f:facet>
                                    </h:panelGrid>
                                </pe:masterDetailLevel>
                            </pe:masterDetail>     
                        </p:panel>
                        </p:panel>

                        <h:panelGrid style="vertical-align: top" columns="1" cellpadding="0" cellspacing="0" rowClasses="panelGridId" border="0" >
                            <p:panel header="#{bundle.cusledgen}">
                                <p:outputPanel autoUpdate="true">
                                <h:panelGrid columns="3" cellpadding="0" cellspacing="10" style="width:100%;">

                                    <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value=":"/>
                                    <h:outputText style="padding: 0 75px 0 0;"  value="#{savingBean.saving.customer.customerName}" />
                                    
                                    <h:outputLabel value= "#{bundle.aliasName}" /><h:outputLabel value=":"/>
                                    <h:outputText rendered="true" value="#{savingBean.saving.customer.aliasName}" />
                                    
                                    <h:outputLabel value= "#{bundle.phone}" /><h:outputLabel value=":"/>
                                    <h:outputText value="#{savingBean.saving.customer.phone}"/> 
                                    
                                    <h:outputLabel value= "#{bundle.mobilePhone}" /><h:outputLabel value=":"/>
                                    <h:outputText value="#{savingBean.saving.customer.mobilePhone}"/>
                                    
                                    <h:outputLabel style="padding: 0 15px 0 0;"  value= "#{bundle.npwp}" /><h:outputLabel value=":"/>
                                    <h:outputText value="#{savingBean.saving.customer.npwp}" />
                                    
                                    <h:outputLabel style="padding: 0 15px 0 0;"  value= "#{bundle.addressRes}" /><h:outputLabel value=":"/>
                                    <h:outputText value="#{savingBean.saving.customer.idAddressLine1}" />
                                    
                                    <h:outputLabel value= "#{bundle.specimen}" /><h:outputLabel value=":"/>
                                    <p:graphicImage  value="/upload/personal/#{savingBean.saving.customer.specimen}" />
                                    
                                </h:panelGrid>
                                </p:outputPanel>
                            </p:panel>
                            
                            <p:panel header="#{bundle.savprodLedgend}" id="savSaprodInfo">
                                
                                <h:panelGrid columns="3" cellpadding="0" cellspacing="10" style="width: 100%;" >
                                    <h:outputLabel value= "#{bundle.savprod}" /><h:outputLabel value=":"/>
                                    <h:outputText rendered="true" value="#{savingBean.saving.savprod.productName}" />

                                    <h:outputLabel value= "#{bundle.minFirstDeposit}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.saving.savprod.minFirstDeposit}" >
                                        <f:convertNumber groupingUsed="true" maxFractionDigits="4"/>
                                    </h:outputText>

                                    <h:outputLabel value= "#{bundle.minRegDeposit}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.saving.savprod.minRegDeposit}" >
                                        <f:convertNumber groupingUsed="true" />
                                    </h:outputText>
                                    
                                    <h:outputLabel value= "#{bundle.interestTax}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.getInterestTaxName(savingBean.saving.savprod.interestTaxId)} %" />
                                        
                                    <h:outputLabel value= "#{bundle.interestMethod}" /><h:outputLabel value=":"/>
                                    <h:outputText value="#{constantaBean.getInterestMetodText(savingBean.saving.savprod.interestMethod)}" />

                                    <h:outputLabel style="padding: 0 15px 0 0;" value= "#{bundle.maxBalAdmFee}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.saving.savprod.maxBalAdmFee}" >
                                        <f:convertNumber groupingUsed="true" />
                                    </h:outputText>
                                    <h:outputLabel value= "#{bundle.admFee}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.saving.savprod.admFee}" >
                                        <f:convertNumber groupingUsed="true" />
                                    </h:outputText>
                                    <h:outputLabel value= "#{bundle.closingAdmFee}" /><h:outputLabel value=":"/>
                                    <h:outputText styleClass="numPos" value="#{savingBean.saving.savprod.closingAdmFee}" >
                                        <f:convertNumber groupingUsed="true" />
                                    </h:outputText>
                                </h:panelGrid>
                            </p:panel>    
                        </h:panelGrid>
                        
                    </h:panelGrid>
                </h:panelGrid>
            </h:form>
        </ui:composition>
    </h:body>
</html>